function GetRequest() {  
    let url = location.search; //获取url中"?"符后的字串
    let theRequest = {};
    let strs = []
    if (url.indexOf("?") != -1) {
        let str = url.substr(1);
       strs = str.split("&");
       for(var i = 0; i < strs.length; i ++) {
          theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
       }
    }
    return theRequest;
 }

var prepareLData = {}
var typeList = []
var tradeList = []
var educationList = []
var natureList = []
var experienceList = []
var tagList = []
var sizeList = []
var region = []
var positionList = []
var abilityList = []
var languageList = []
var resumeStatusList = []
function indexprepare(callback, type, data){
   var vm = this
   var url = type==1 ? "person/resume/prepare" : "person/index/prepare"
   var p = {
      
   }
   request(url,'GET',JSON.stringify({}),function(res){
      prepareLData =  $.extend(prepareLData, res.data)
      // if(type==1){
      //    indexprepare(callback, 2, res.data)
      //    return
      // }  

      // if(type==2){
      //    debugger
      //    res.data = $.extend(data, res.data)
      // }
      typeList = prepareLData.type
      tradeList = prepareLData.trade
      educationList = prepareLData.education
      natureList = prepareLData.nature
      experienceList = prepareLData.experience
      tagList = prepareLData.tag
      sizeList = prepareLData.size
      resetAreaName(prepareLData.region)
      region = prepareLData.region
      abilityList = prepareLData.ability
      languageList = prepareLData.language
      positionList = prepareLData.position
      resumeStatusList = prepareLData.status
      salaryList = prepareLData.salary
      if(callback){
         callback(prepareLData)
      }
   },function(err){
      
   })
}

function resetAreaName(list){
   for(var i=0; i<list.length; i++){
      list[i].name = list[i].region_name
      if(list[i].second||list[i].third||list[i].children){
         resetAreaName(list[i].second||list[i].third||list[i].children)
      }
   }
}
function getTypeName(id, list){
   list = list || typeList
   for(var i=0; i<typeList.length; i++){
      if(typeList[i].id==id){
         return typeList[i].name
      } 
   }
   return ""
}


function getLanguageName(id, list){
   list = list || languageList
   for(var i=0; i<list.length; i++){
      if(list[i].id==id){
         return list[i].name
      } 
   }
   return ""
}
function getResumeStatusListName(id, list){
   list = list || resumeStatusList
   for(var i=0; i<list.length; i++){
      if(list[i].id==id){
         return list[i].name
      } 
   }
   return ""
}
function getAbilityName(id, list){
   list = list || abilityList
   for(var i=0; i<list.length; i++){
      if(list[i].id==id){
         return list[i].name
      } 
   }
   return ""
}
function getNatureName(id, list){
   list = list || natureList
   for(var i=0; i<list.length; i++){
      if(list[i].id==id){
         return list[i].name
      } 
   }
   return ""
}
function getTradeName(id, list){
   list = list || tradeList
   var tmp , val
   for(var i=0; i<list.length; i++){
      tmp = list[i]
      if(tmp.id==id){
         return tmp.name
      } else if(tmp.children){
         val = getTradeName(id, tmp.children)
         if(val){
            return val
         }
      }
   }
   return ""
}

function getPositionName(id, list){
   list = list || positionList
   var tmp , val
   for(var i=0; i<list.length; i++){
      tmp = list[i]
      if(tmp.id==id){
         return tmp.name
      } else if(tmp.children){
         val = getPositionName(id, tmp.children)
         if(val){
            return val
         }
      }
   }
   return ""
}

function searchPositionName(name,list,vals){
   list = list || positionList
   vals = vals || []
   var tmp , val 
   for(var i=0; i<list.length; i++){
      tmp = list[i]
      if(tmp.name.indexOf(name) != -1){
         vals.push(tmp)
         return vals
      } else if(tmp.second||tmp.third||tmp.children){
         val = searchPositionName(name, tmp.second||tmp.third||tmp.children, vals)
         if(val.length>0){
            vals.push(tmp)
            return vals
         }
      }
   }
   
   return vals
}

function getAreaName(id, list, vals){
   list = list || region
   vals = vals || []
   var tmp , val 
   for(var i=0; i<list.length; i++){
      tmp = list[i]
      if(tmp.id==id){
         vals.push({
            id: tmp.id,
            name: tmp.name
         })
         return vals
      } else if(tmp.second||tmp.third||tmp.children){
         val = getAreaName(id, tmp.second||tmp.third||tmp.children, vals)
         if(val.length>0){
            vals.push({
               id: tmp.id,
               name: tmp.name
            })
            return vals
         }
      }
   }
   return vals
}
function getEducationName(id, list){
   list = list || educationList
   for(var i=0; i<list.length; i++){
      if(list[i].id==id){
         return list[i].name
      } 
   }
   return ""
}
function getExperienceName(id, list){
   list = list || experienceList
   for(var i=0; i<list.length; i++){
      if(list[i].id==id){
         return list[i]
      } 
   }
   return ""
}

function getWelfareName(id, list){
   list = list || tagList
   for(var i=0; i<list.length; i++){
      if(list[i].id==id){
         return list[i].name
      } 
   }
   return ""
}

function getsalaryId(min,max){
   var minArr = salaryList.filter(function(item){
      return item.min == min
   })
   if(!minArr.length){
      return ''
   }
   var data = minArr.filter(function(item){
      return item.max == max
   })

   if(data.length){
      return data[0].id
   }else{
      return ""
   }

}

function getsalaryName(id){
   var data = salaryList.filter(function(item){
      return item.id == id
   })
   if(data.length){
      return data[0]
   }else{
      return {
         max:'',
         min:''
      }
   }
}

function getSizeName(id, list){
   list = list || sizeList
   for(var i=0; i<list.length; i++){
      if(list[i].id==id){
         return list[i].name
      } 
   }
   return ""
}

function lcheckLogin(vm){
   if(!getToken()){
      vm.$message("请先登录");
      setTimeout(function(){
         location.href = "01.html"
      }, 2000)
      return false
   }
   return true
}

//匹配邮箱格式
function checkEmail(str){
   var re = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/; 
   if (re.test(str)) {
     return true
   } else {
      return false
   }
}
